package com.cms.image.action;

import java.util.ArrayList;
import java.util.List;

import com.cms.image.model.ImageType;
import com.jframe.sys.controller.ExtendAction;
import com.jframe.sys.controller.utils.DicCache;
import com.jframe.sys.controller.utils.JsBuilder;
import com.jframe.sys.controller.utils.TabmCache;
import com.jframe.sys.utils.CalendarUtil;
import com.jframe.sys.utils.JsonUtil;
import com.jframe.sys.utils.StringUtil;
import com.jframe.sys.webui.Columns;
import com.jframe.sys.webui.Editor;
import com.jframe.sys.webui.Grid;

public class ImageTypeAction extends ExtendAction {
	private static String ACTION="imageTypeAction";
	private static String SERVICE = "imageTypeService";
	private static Class<ImageType> CLAZZ = ImageType.class;
	public void list(){
		List<Columns> frozenColumns = new ArrayList<Columns>();// 固定列
		List<Columns> commonColumns = new ArrayList<Columns>();// 活动列
		 
		frozenColumns.add(new Columns("ck", "", 40, ""));
		frozenColumns.add(new Columns("id", "编号", 100, ""));
		frozenColumns.add(new Columns("groupName", "图片组名称", 150, ""));		
		commonColumns.add(new Columns("upId", "父类别", 120, new Editor("combobox",true),DicCache.getComboboxJson("sm_cms_imageType")));
		commonColumns.add(new Columns("createTime", "组创建时间", 120, ""));
		commonColumns.add(new Columns("publisher", "图片发布人", 120, ""));
		commonColumns.add(new Columns("active", "有效否", 120, new Editor("combobox",true),DicCache.getComboboxJson("dm_sys_active")));
		commonColumns.add(new Columns("memo", "组图片描述", 320, ""));
		
		Grid grid = new Grid();
		grid.setUrl(this.getUrl(ACTION+".do?method=load"));
		String js = JsBuilder.getJsStr(frozenColumns, commonColumns, grid);
		this.request.setAttribute("js", js);
		this.forward("/cms/image/list/imageTypeList.jsp");
	}
	
	public void load(){
		baseLoad(SERVICE, CLAZZ);
	}
	
	public void save() {
		baseSave(SERVICE, CLAZZ);
	}
	
	public void afterSave(Object obj){
		TabmCache.reload("sm_cms_imageType");
	}

	public void delete() {
		baseDelete(SERVICE);
	}
	
	public void afterDelete(String ids){
		TabmCache.reload("sm_cms_imageType");
	}

	public void getObjById() {
		int id=StringUtil.parseInt(request.getParameter("id"));
		Object obj = this.getObject(SERVICE);
		ImageType imageType = null ;
		if(id>0){
			print(JsonUtil.obj2Json(obj));
		}else{
			imageType = new ImageType();
			imageType.setPublisher(this.getCurUser().getUserName());
			imageType.setCreateTime(CalendarUtil.getDateTime());
			print(JsonUtil.obj2Json(imageType));
		}
		
	}
}
